﻿using SuperJoe.Framework.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Mvc.Filters;

namespace SuperJoe.Framwork.Web
{
    [Authorize]
    public abstract class AuthorizationController : BaseController
    {
        public IdentityUser CurrentUser
        {
            get; private set;
        }

        protected override void OnAuthentication(AuthenticationContext filterContext)
        {
            base.OnAuthentication(filterContext);
            if (IdentityManager.IsAuthenticated)
            {
                this.CurrentUser = IdentityManager.GetUser();
                ViewBag.CurrentUser = this.CurrentUser;
                SuperJoeContext.Current = new SuperJoeContext()
                {
                    UserId = this.CurrentUser.Id,
                    Name = this.CurrentUser.Name,
                };
            }
        }
    }
}
